package hibari.server.servlet;

import hibari.client.model.DownloadToken;

public class JsonTemplate
{
  protected static String nl;
  public static synchronized JsonTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    JsonTemplate result = new JsonTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "{" + NL + "\t\"state\": \"ok\"," + NL + "\t\"weekNumber\": ";
  protected final String TEXT_2 = NL + "}";
  protected final String TEXT_3 = NL + "{" + NL + "\t\"state\": \"error\"" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     
DownloadToken token = (DownloadToken) argument;

     if(token != null) { 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(token.getWeekNumber() );
    stringBuffer.append(TEXT_2);
     } else { 
    stringBuffer.append(TEXT_3);
     } 
    return stringBuffer.toString();
  }
}
